﻿using System;

namespace RestUpMVC.Resource
{
    internal class ResourceParentResolver : IResourceMetaDataResolver
    {
        #region Implementation of IResourceMetaDataResolver

        public void ResolveMetaData(Type resourceType, ResourceMetaData resourceMetaData)
        {
            if (resourceType == null) throw new ArgumentNullException("resourceType");
            if (resourceMetaData == null) throw new ArgumentNullException("resourceMetaData");

            object[] attributes = resourceType.GetCustomAttributes(typeof (ChildOfAttribute), false);
            if (attributes.Length.Equals(0))
            {
                return;
            }

            resourceMetaData.ParentResource = (attributes[0] as ChildOfAttribute).ParentResource;
        }

        #endregion
    }
}